Pass by value, pass by reference, pass by pointers.

Pass by value

Pass by reference

  • have a look at code to understand.
    
    	#include<iostream>
    	void change_var(int &a) //here a is an reference to variable 'x'
    	{
    	a++;
    	}
    
    	int main()
    	{
    	int x=20;
    	std::cout<<x<<std::endl; //will print 20
    	change_var(x);
    	std::cout<<x<<std::endl;  //will print 21
    	return 0;
    	}
    

    Output
    address of x is 0x7ffcd5f30234
    21
    address after calling function is 0x7ffcd5f30238

    Note that the address increase by 4, since now pointer points to next memory which is 4 blocks away (integer takes 4 bytes).